import java.util.Arrays;

public class IShellSort {
    //插入排序之希尔排序；
    public static void shellSort(int[] array){
        int gap= array.length;
        while(gap>0){
            gap/=2;
            fun(array,gap);
        }
    }
    public static void fun(int[] array,int gap){
        for(int i=gap;i<array.length;i++){
            int tmp=array[i];
            int j=i-gap;
            for(;j>=0;j-=gap){
                if(array[j]>tmp){
                    array[j+gap]=array[j];
                }else{
                    break;
                }
            }
            array[j+gap]=tmp;
        }
    }
    public static void main(String[] args){
        int[] array={9,1,2,5,7,4,8,6,3,5};
        shellSort(array);
        System.out.println(Arrays.toString(array));
    }

}
